package com.repair.controller;


import com.repair.entity.Vo.RepairOrder;
import com.repair.entity.model.Application;
import com.repair.entity.model.ApplicationForRepair;
import com.repair.entity.model.TeacherUser;
import com.repair.service.ApplicationForRepairService;
import com.repair.service.ApplicationService;
import com.repair.service.TeacherUserService;
import com.repair.util.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 报修申请 前端控制器
 * </p>
 *
 * @author tianwenle
 * @since 2023-04-12
 */
@RestController
@RequestMapping("/application-for-repair")
public class ApplicationForRepairController {

    @Autowired
    private TeacherUserService teacherUserService;

    @Autowired
    private ApplicationService applicationService;

    @Autowired
    private ApplicationForRepairService applicationForRepairService;



    public R get(){
        // 最终传输的数据
        List<Map> list = new ArrayList();

        // 所有维修的东西
        List<ApplicationForRepair> applicationForRepairs = applicationForRepairService.list();

        for (ApplicationForRepair applicationForRepair : applicationForRepairs) {

            Map map = new HashMap<>();
            RepairOrder repairOrder = new RepairOrder();

            String teacherNo = applicationForRepair.getTeacherNo();
            map.put("teacherNo",teacherNo);

            TeacherUser teacherUser = teacherUserService.getById(teacherNo);


            String phone = teacherUser.getPhone();
            map.put("phone",phone);
            String teacherName = teacherUser.getTeacherName();
            map.put("teacherName",teacherName);

            String faultDescription = applicationForRepair.getFaultDescription();
            map.put("teachfaultDescriptionerName",faultDescription);
            String faultPicture = applicationForRepair.getFaultPicture();
            map.put("faultPicture",faultPicture);
            String repairOrderNo = applicationForRepair.getRepairOrderNo();
            map.put("repairOrderNo",repairOrderNo);

            LocalDate dateOfRepairRequest = applicationForRepair.getDateOfRepairRequest();
            map.put("dateOfRepairRequest",dateOfRepairRequest);

            Integer applicationForRepairId = applicationForRepair.getApplicationForRepairId();

            Application application = applicationService.getById(applicationForRepairId);

            String repairFacilities = application.getRepairFacilities();
            map.put("repairFacilities",repairFacilities);

            String location = application.getLocation();
            map.put("location",location);

            LocalDateTime createTime = applicationForRepair.getCreateTime();
            map.put("createTime",createTime);

            LocalDateTime updateTime = applicationForRepair.getUpdateTime();
            map.put("updateTime",updateTime);

            list.add(map);

        }


        return R.ok().data("list",list);
    }


}

